package com.zhijiang.hospital.controller;

import com.zhijiang.config.result.R;
import com.zhijiang.config.webConfig.PassToken;
import com.zhijiang.hospital.entity.ArrangerClass;
import com.zhijiang.hospital.entity.Checkin;
import com.zhijiang.hospital.entity.dto.ArrDto;
import com.zhijiang.hospital.entity.dto.CheckDto;
import com.zhijiang.hospital.service.ArrangerClassService;
import com.zhijiang.util.ArrangerClassQuery;
import com.zhijiang.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.*;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_datas
 * @description
 * @date 2023-04-11 09:24:16
 */
@RestController
@RequestMapping("ArrangeClass")
public class ArrangeClassController {
    @Autowired
    private ArrangerClassService arrangerClassService;

    @PostMapping("getArrangeClass")
    public R getArrangeClass(@RequestBody ArrangerClassQuery arrangerClassQuery) {
        PageList<ArrangerClass> arrangerClass = arrangerClassService.getArrangerClass(arrangerClassQuery);
        return R.ok(arrangerClass);
    }


    @PostMapping("contrast")
    public R contrast(@RequestBody ArrangerClassQuery arrangerClassQuery) throws ParseException {
        PageList<ArrangerClass> arrangerClass = arrangerClassService.contrast(arrangerClassQuery);
        return R.ok(arrangerClass);
    }


    @PostMapping("contrast1")
    @PassToken
    public R contrast1(@RequestBody ArrangerClassQuery arrangerClassQuery) throws ParseException {
        Map<String, List<ArrangerClass>> a = arrangerClassService.contrast1(arrangerClassQuery);


        ArrayList<ArrDto> arrDtos = new ArrayList<>();

        for (String s : a.keySet()) {
            ArrayList<String> list = new ArrayList<>();
            ArrayList<String> list1 = new ArrayList<>();
            ArrDto arrDto = new ArrDto();
            arrDto.setDept(s);
            List<ArrangerClass> arrangerClasses = a.get(s);
            for (ArrangerClass arrangerClass : arrangerClasses) {

                System.out.println(arrangerClass);
                if (Objects.isNull(arrangerClass.getSquenceName())) {
                    list.add(arrangerClass.getEmpName() + "(暂无排班、" + arrangerClass.getEmplType() + "、" + arrangerClass.getMorningCheckType() + "、" + arrangerClass.getAfternoonCheckType() + ")");
                } else {
                    list.add(arrangerClass.getEmpName() + "(" + arrangerClass.getEmplType() + "、" + arrangerClass.getSquenceName() + "、" + arrangerClass.getMorningCheckType() + "、" + arrangerClass.getAfternoonCheckType() + ")");
                }
                //    list.add(arrangerClass.getEmpName()+"("+arrangerClass.getEmplType()+"、"+arrangerClass.getSquenceName()+")");
                list1.add(arrangerClass.getEmpName() + "(" + arrangerClass.getEmplType() + "、" + arrangerClass.getCheckType() + ")");

            }
            arrDto.setArrangerClasses(list);
            arrDto.setChecks(list1);
            arrDtos.add(arrDto);
        }
//        CheckDto checkDto = new CheckDto();
//        checkDto.setArrangerClasses(a);

        return R.ok(arrDtos);
    }


    @GetMapping("deptAll")
    @PassToken
    //11
    public R deptAll() {
        List<String> strings = arrangerClassService.deptAll();
        strings.add(0, "全部打卡科室");
        return R.ok(strings);
    }
}
